package cn.com.eado.crm.m.db

import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverter
import androidx.room.TypeConverters
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

@Entity(tableName = "hang_ye")
@TypeConverters(HangYe.Converters::class)
data class HangYe(
    @PrimaryKey(autoGenerate = true)
    var id: Int,
    var name: String,
    var types: List<Type>
){
    data class Type(
        var name: String
    )

    class Converters{
        @TypeConverter
        fun stringToObject(value: String): List<Type> {
            val listType = object : TypeToken<List<Type>>() {
            }.type
            return Gson().fromJson(value, listType)
        }

        @TypeConverter
        fun objectToString(list: List<Type>): String {
            val gson = Gson()
            return gson.toJson(list)
        }
    }
}